import 'package:dio/dio.dart';
import '../../public.dart';
import '../api_code.dart';

/// Log 拦截器
class LogsInterceptors extends InterceptorsWrapper {
  @override
  onRequest(RequestOptions options) async {
    LogUtil.v("请求url：${options.path}");
    LogUtil.v('请求头: ' + options.headers.toString());
    if (options.data != null) {
      LogUtil.v('请求参数data: ' + options.data.toString());
    }
    if (options.queryParameters != null) {
      LogUtil.v('请求参数query: ' + options.queryParameters.toString());
    }

    return options;
  }

  @override
  onResponse(Response response) async {
    if (response != null) {
      // print('返回数据: ' + response.toString());
    }
    return response;
  }

  @override
  onError(DioError err) async {
    LogUtil.v('请求异常: ' + err.toString());
    LogUtil.v('请求异常信息: ' + err.response?.toString() ?? "");
    ApiCode.errorHandleFunction(ApiCode.NETWORK_ERROR, '', false);
    return err;
  }
}
